package com.study.mq;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author: chenhs
 * @date: Created in 10:28 2019/12/2
 **/
@Configuration
public class RabbitConfig {

    public static final String DIRECT_ROUTING_KEY_recvqueue = "recvqueue";

    public static final String DIRECT_ROUTING_KEY_sendqueue = "sendqueue";

    /**
     * 创建队列 - 读取队列
     * @return
     */
    @Bean
    public Queue recvQueue() {
        Queue queue = new Queue(DIRECT_ROUTING_KEY_recvqueue, true);
        return queue;
    }

    /**
     * 创建队列 - 发送队列
     */
    @Bean
    public Queue sendQueue() {
        return new Queue(DIRECT_ROUTING_KEY_sendqueue, true);
    }

    /**
     * 创建交换器
     * @return
     */
    @Bean
    public DirectExchange exchange(){
        return new DirectExchange("directExchange");
    }

    /**
     * 队列绑定并关联到ROUTINGKEY
     * @return
     */
    @Bean
    public Binding binding() {
        return BindingBuilder.bind(sendQueue()).to(exchange()).withQueueName();
    }

}
